package com.rose.sharding.controller;

import com.rose.sharding.entity.User;
import com.rose.sharding.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: zhu.chen
 * @date: 2020/10/29
 * @version: v1.0.0
 */
@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;

    /**
     * http://localhost:8083/sharding/insert?username=shawujing&password=s123456
     */
    @GetMapping("/insert")
    public String insert(@RequestParam("username") String username, @RequestParam("password") String password) {
        userMapper.insert(new User(username, password));
        return "ok";
    }

    /**
     * http://localhost:8083/sharding/select?username=xiaohong
     */
    @GetMapping("/select")
    public User select(@RequestParam("username") String username) {
        return userMapper.select(username);
    }

    /**
     * http://localhost:8083/sharding/selectAll
     */
    @GetMapping("/selectAll")
    public List<User> selectAll() {
        return userMapper.selectAll();
    }

}
